#!/bin/bash
#修改all_config.yaml中的通信配置
CONFIG_FILE="./all_config.yaml"

eval $(awk '
BEGIN { FS = ": "; RS = "\n"; }
{
    gsub(/^[ \t]+|[ \t]+$/, "", $1);
    gsub(/^[ \t]+|[ \t]+$/, "", $2);
    if ($1 ~ /^[a-zA-Z_][a-zA-Z0-9_]*$/) {
        print toupper($1) "=" "\"" $2 "\"";
    }
}
' "$CONFIG_FILE")

# START_IP=10
# NETWORK_PREFIX="192.168.205."
# NETMASK="255.255.255.0"
# GATEWAY="192.168.205.1"
# NETDETECT="192.168.205.1"

for i in {0..7}
do
    CURRENT_IP=$((START_IP + i))
    FULL_IP="${NETWORK_PREFIX}${CURRENT_IP}"
    echo "Setting IP for card $i to $FULL_IP"
    hccn_tool -i $i -ip -s address $FULL_IP netmask $NETMASK

    echo "Setting gateway for card $i to $GATEWAY"
    hccn_tool -i $i -gateway -s gateway $GATEWAY

    echo "Setting netdetect for card $i to $NETDETECT"
    hccn_tool -i $i -netdetect -s address $NETDETECT
done